#include "binarytree.h"

NodePtr BinaryTree::insertRecursive(NodePtr node, int value) {
	if (node == nullptr) {
		return new TreeNode(value);
	}
	
	if (value < node->data) {
		node->childLeft = insertRecursive(node->childLeft, value);
	} else if (value > node->data) {
		node->childRight = insertRecursive(node->childRight, value);
	}
	
	return node;
}

void BinaryTree::preorderRecursive(NodePtr node) const {
	if (node == nullptr) {
		return;
	}
	
	std::cout << node->data << " ";
	preorderRecursive(node->childLeft);
	preorderRecursive(node->childRight);
}

void BinaryTree::clearRecursive(NodePtr node) {
	if (node == nullptr) return;
	
	clearRecursive(node->childLeft);
	clearRecursive(node->childRight);
	delete node;
}
